package entities;

import java.io.Serializable;
import java.util.Date;

import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.MappedSuperclass;
import javax.persistence.PrePersist;
import javax.persistence.PreUpdate;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

import enums.Flag;

@MappedSuperclass
public abstract class EntityMother implements Serializable {

	private static final long serialVersionUID = 1L;

	@Temporal(TemporalType.TIMESTAMP)
	private Date dateDeleted;
	
	@Temporal(TemporalType.TIMESTAMP)
	private Date dateCreated;
	
	@Temporal(TemporalType.TIMESTAMP)
	private Date dateUpdated;
	  
	@Enumerated(EnumType.STRING)
	private Flag oneFlag;
	
	@PrePersist
	public void prePersist(){
		this.setDateCreated(new Date());
		this.setDateUpdated(new Date());
		this.setOneFlag(Flag.activated);
	}
	  
	@PreUpdate
	public void preUpdate(){
		this.setDateUpdated(new Date());
	}  
	
	public Flag getOneFlag() {
		return oneFlag;
	}

	public void setOneFlag(Flag oneFlag) {
		this.oneFlag = oneFlag;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((oneFlag == null) ? 0 : oneFlag.hashCode());
		return result;
	}
	
	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		EntityMother other = (EntityMother) obj;
		if (oneFlag == null) {
			if (other.oneFlag != null)
				return false;
		} else if (!oneFlag.equals(other.oneFlag))
			return false;
		return true;
	}

	public Date getDateDeleted() {
		return dateDeleted;
	}

	public void setDateDeleted(Date dateDeleted) {
		this.dateDeleted = dateDeleted;
	}

	public Date getDateCreated() {
		return dateCreated;
	}

	public void setDateCreated(Date dateCreated) {
		this.dateCreated = dateCreated;
	}

	public Date getDateUpdated() {
		return dateUpdated;
	}

	public void setDateUpdated(Date dateUpdated) {
		this.dateUpdated = dateUpdated;
	}	
}